package com.fcy.myapplicati

import android.app.Dialog
import android.content.Context

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Log.d(TAG, "onCreate: $window")
        Dia(this).show(supportFragmentManager, "d")
    }

    class Dia(val co: Context) : BottomSheetDialogFragment() {

        override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
            val dia = super.onCreateDialog(savedInstanceState)
            dia.setContentView(R.layout.container)
            dia.findViewById<FrameLayout>(R.id.design_bottom_sheet).apply {

                val inflate = LayoutInflater.from(co).inflate(R.layout.value, this, false)
                addView(inflate)
            }
            val from =
                BottomSheetBehavior.from(dia.findViewById<FrameLayout>(R.id.design_bottom_sheet) as FrameLayout)
            from.state = BottomSheetBehavior.STATE_EXPANDED
            return dia
        }

        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setStyle(STYLE_NORMAL, R.style.CustomDialogStyle)
        }

    }
}

private const val TAG = "MainActivity"